/*
 * Copyright 2007. Mount Sinai Hospital, Toronto, Canada.
 * 
 * Licensed under the GNU Lesser General Public License, Version 2. You
 * can find a copy of the license at:
 * 
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
 * 
 * IN NO EVENT SHALL MOUNT SINAI HOSPITAL BE LIABLE TO ANY PARTY FOR DIRECT, 
 * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST 
 * PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, 
 * EVEN IF MOUNT SINAI HOSPITAL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
 * DAMAGE.
 * 
 * MOUNT SINAI HOSPITAL SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF 
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND 
 * ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". 
 * MOUNT SINAI HOSPITAL HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 
 * UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 
 */
package com.sinai.mshab.client.user;

import com.google.gwt.user.client.Cookies;
import com.google.gwt.user.client.rpc.IsSerializable;
import com.sinai.mshab.client.ui.aggregate.FormData;

/**
 * Stores information about the current user.
 * @author serge
 */
public class User implements IsSerializable {
	
	private String username;
	private String permission;
	
	/**
	 * @param username the username to set
	 */
	public void setUsername(String u) {
		username = u;
	}
	
	/**
	 * @return the username
	 */
	public String getUsername() {
		return username;
	}
	
	/**
	 * @param permission the permission to set
	 */
	public void setPermission(String p) {
		permission = p;
	}
	
	/**
	 * @return the permission
	 */
	public String getPermission() {
		return permission;
	}
	
	public static String getUserPermission() {
		String cookie = Cookies.getCookie(FormData.getServletUrl() + " cookie");
		if (cookie == null) {
			return null;
		}
		return cookie;
	}

	/**
	 * Check if user can login via cookie and avoid login screen
	 * 
	 * @return true if user has a valid cookie
	 */
	public static boolean loggedIn() {
		String cookie = Cookies.getCookie(FormData.getServletUrl() + " cookie");
		if (cookie == null) {
			return false;
		}
		return true;
	}
}
